//
//  ZPMineTiaokeVC.m
//  ZPIOSEducation
//
//  Created by 李伟 on 2017/1/15.
//  Copyright © 2017年 mini1. All rights reserved.
//

#import "ZPMineTiaokeVC.h"
#import "ZPMineChooseVC.h"
#import "ZPSelectClassVC.h"
#import "ZPSelectCurriculumCell.h"

static NSString  * const reuseIdentifier = @"ZPSelectCurriculumCell";

@interface ZPMineTiaokeVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
{

}
@property (strong, nonatomic) UICollectionView *collectionView;
@property (strong, nonatomic) UICollectionViewFlowLayout *layout;
@property (weak, nonatomic) IBOutlet UIView *calendarView;
@property (strong, nonatomic) ZPSelectCurriculumCell *cell;
@property (copy, nonatomic) NSArray *numbers;

@end

@implementation ZPMineTiaokeVC
-(ZPSelectCurriculumCell *)cell
{
    if (_cell == nil) {
        _cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZPSelectCurriculumCell class]) owner:self options:nil] lastObject];
    }
    return _cell;
}

- (UICollectionViewFlowLayout *)layout { //CollectionView布局
    if (_layout == nil) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
    }
    return _layout;
}

- (UICollectionView *)collectionView
{
    if (_collectionView == nil) {
        _collectionView = [[UICollectionView alloc] initWithFrame:self.calendarView.bounds collectionViewLayout:self.layout];
        _collectionView.backgroundColor = zColor(84, 185, 240);
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([ZPSelectCurriculumCell class]) bundle:nil] forCellWithReuseIdentifier:reuseIdentifier];
    }
    return _collectionView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.numbers = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12"];
    [self.calendarView addSubview:self.collectionView];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.title = @"调课";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zhenpin_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClick)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(chooseButonClick)];
    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:@{NSFontAttributeName:Z15,NSForegroundColorAttributeName:white_color} forState:UIControlStateNormal];
}
- (void)backButtonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)chooseButonClick
{
    ZPMineChooseVC *vc = [[ZPMineChooseVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { //单元个数
    return 12;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZPSelectCurriculumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.numberLab.text = self.numbers[indexPath.row];
    [cell.numberBtn setImage:Z_IMAGE(@"back_xz") forState:UIControlStateNormal];
    [cell.numberBtn setImage:Z_IMAGE(@"back_xz") forState:UIControlStateSelected];
    return cell;
}

//- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    ZPSelectCurriculumCell *cell = (ZPSelectCurriculumCell *)[collectionView cellForItemAtIndexPath:indexPath];
////    [cell UpdateCellWithState:!cell.isSelected];
//}


// 返回collectionView里的某个组里item最小行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

//  返回collectionView里的某个组里item最小列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

// 返回collectionView里的某个section的item大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.calendarView.xj_width/6, self.calendarView.xj_height/2);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)nextStepClick:(id)sender
{
    ZPSelectClassVC * vc = [[ZPSelectClassVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

@end
